import { useUser } from "@/stores/useUser";
import { useEquip } from "@/stores/useEquip";
import { adminURL, authURL } from "@/configs/jy";
import { equipSocketSend, isRegistered } from "@/services/equip-socket";

let count = 0;
// 执行系统任务
export const systemTaskRun = () => {
    const userStore = useUser();
    count++;
    if (count % 3 == 0) {
        const equipStore = useEquip();
        equipStore.addEquipData({ funid: "test1", online: true, dtAIValues: [25, 50, 20, 50, (60 + Math.floor(Math.random() * 15)) / 10, 50000, (50 + Math.floor(Math.random() * 250)) / 100, 900], dtDIValues: [], dtDOValues: [] });
    }
    if (count % 600 == 0) {
        // 10分钟
        userStore.syncToken().catch(() => {
            location.href = authURL + "/#/?url=" + adminURL + "/#/client_type=pc_admin&storage=true";
        });
    }
    if (count % 30 == 0 && isRegistered) {
        // 30秒
        equipSocketSend({ infotype: "register", info: "" });
        // nowEquipHook.state.funid && equipSocketSend({ infotype: "damopr", info: { opr: "read", unid: nowEquipHook.state.funid, cnt: 10, cycletime: 3000 } });
    }
};
// 重置计时
export const systemTaskReset = () => (count = 0);
